package com.yuma.tingshu.user.api;

import com.yuma.tingshu.common.annotation.YuMaLogin;
import com.yuma.tingshu.common.result.Result;
import com.yuma.tingshu.user.service.UserListenProcessService;
import com.yuma.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserListenProcessApiController {

    @Autowired
    private UserListenProcessService userListenProcessService;

    /**
     * 获取声音的播放进度
     * @param trackId
     * @return
     */
    @YuMaLogin(required = false)
    @GetMapping("/getTrackBreakSecond/{trackId}")
    public Result<BigDecimal> getTrackBreakSecond(@PathVariable Long trackId) {
        BigDecimal result = userListenProcessService.getTrackBreakSecond(trackId);
        return Result.ok(result);
    }

    /**
     * 更新播放进度
     * @param userListenProcessVo
     * @return
     */
    @YuMaLogin(required = false)
    @PostMapping("/updateListenProcess")
    public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo) {
        userListenProcessService.updateListenProcess(userListenProcessVo);
        return Result.ok();
    }

    /**
     * 获取最近播放的声音
     * @return
     */
    @YuMaLogin(required = false)
    @GetMapping("/getLatelyTrack")
    public Result<Map<String, Long>> getLatelyTrack() {
        Map<String, Long> result = userListenProcessService.getLatelyTrack();
        return Result.ok(result);
    }

}

